/* $Id: UserRoleFacadeImpl.java 
 * Copyright (C) 2011, TRAKHEES
 *  
 * Revision History
 *
 * Date  			Author 		    	Remarks
 * ---------------------------------------------------------------------------------
 *
 */
package ae.pcfc.etks.online.common.facade.provider;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.springframework.transaction.annotation.Transactional;

import ae.pcfc.etks.online.common.domain.Client;
import ae.pcfc.etks.online.common.domain.User;
import ae.pcfc.etks.online.common.domain.manager.UserRoleDomainObjectManager;
import ae.pcfc.etks.online.common.facade.UserRoleFacade;
import ae.pcfc.etks.online.common.vo.UserVO;

public class UserRoleFacadeImpl extends BaseFacade implements UserRoleFacade{
    	/*
	 * Here we coordinate between the all interacting business domain objects
	 * (BO), transactions are maintained here. use case business validation are
	 * maintained here (that requires DB checks or retrieving data from DB)
	 */
	public UserRoleDomainObjectManager userRoleDomainObjectManager;


	/**
	 * setUserRoleDomainObjectManager
	 * 
	 * @param userRoleDomainObjectManager
	 * void
	 */
	public void setUserRoleDomainObjectManager(
			UserRoleDomainObjectManager userRoleDomainObjectManager) {
		this.userRoleDomainObjectManager = userRoleDomainObjectManager;
	}


	//TODO: 
	/**
	 * getClientsList
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UserRoleFacade#getClientsList()
	 * 
	 */
	@Transactional(readOnly = true)
	public List<UserVO> getClientsList() {
		
		List<Client> clients = userRoleDomainObjectManager.getClientsList();
		 
		List<UserVO> userVOs = new ArrayList<UserVO>();
		
		UserVO userVO;
		
		for (int i=0; i<clients.size(); i++)
		{								
		userVO = new UserVO();
		Set<User> users = clients.get(i).getUsers() ;
		Iterator<User> itrNew = users.iterator();
		while(itrNew.hasNext()){
			User user = itrNew.next();
			userVO.setStrUserName(user.getUNameEng());
			userVO.setStrUserNameArab(user.getUNameArb());
			userVO.setStrEmail(user.getUEmail());
			userVO.setStrAccountStatus(user.getUStatus());
		}
		userVO.setStrClientType(clients.get(i).getCType());
		userVOs.add(userVO);
		}
		
		return userVOs;
	}
	

}
